<template>
	<view class="content">
		<view class="top_item">当前时间：{{date}} {{showTime}}</view>
		<view style="background: #F5F7F9; height: 16upx;"></view>
		<view class="formbox">
			<!-- <view class="input_set x-row">
				<view class="x-col-center lefttext"><text>*</tex      t>抵消打卡</view>
				<input type="text" placeholder="请选择" v-model="form.sucer" class="x-col-center x-col inputs" disabled @click="scuer"/>
				<u-icon name="arrow-right" color="#666" size="26"></u-icon>
				<u-select v-model="show" :list="list" @confirm="confirm"></u-select>
			</view> -->
			<view class="input_set" style="border:0; padding-top: 30upx;">
				<view class="x-col-center lefttext"><text>*</text>外出事由</view>
				<textarea v-model="content" placeholder="请输入外出理由…" class="textare"></textarea>
			</view>
		</view>
		<view style="background: #F5F7F9; height: 16upx;"></view>
		<photoLoaction v-if="showpho" @getPhotoSuccess="getPhotoSuccess" @getPhotoFail="getPhotoFail" :address="address"></photoLoaction>
		<view class="formbox">

			<view class="input_set x-row" style="border:0; padding-top: 30upx;" @click="photoCreate">
				<view class="x-col-center x-col lefttext" style="padding-bottom: 10upx;">拍照上传当前情况</view>
				<!-- <u-upload :source-type="stype" ref="uUpload" max-count="8" name="file" :action="action" :auto-upload="true"></u-upload> -->
				<view class="iconfont iconyou x-col-center"></view>
			</view>
			<view class="input_set" v-if="photo.path">
				<image mode="widthFix" style="width: 100%;margin-bottom: 20rpx;" :src="photo.path"></image>
			</view>
		</view>

		<view class="z_button">
			<view class="but" @click="submit">提 交</view>
		</view>
	</view>
</template>

<script>
	import photoLoaction from "../../components/photoLoaction";
	export default {
		components: {
			photoLoaction
		},
		data() {
			return {
				stype:['camera'],//自能使用相机拍照
				show: false,
				action: this.urlimg + "api/Upload/upfile",
				form: {
					sucer: "555"
				},
				list: [{
						value: '1',
						label: '江'
					},
					{
						value: '2',
						label: '湖'
					}
				],
				date: new Date().toISOString().slice(0, 10),
				showTime: '',
				lat: '',
				lon: '',
				content: '',
				showpho:false,
				photo:'',
				address:"",
			}
		},
		onLoad(e) {
			this.lat = e.lat;
			this.lon = e.lon;
		},
		onShow() {
			let that = this;
			let timer = setInterval(function() {
				var date = new Date();
				var h = date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours();
				var m = date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes();
				var s = date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds();
				that.showTime = h + ':' + m + ':' + s
			}, 1000)
		},
		methods: {
			getPhotoSuccess(e) {
				this.photo = e;
				this.showpho = false;
			},
			getPhotoFail(){
				this.showpho=false;
			},
			photoCreate(){
				let that = this;
				that.showpho = true;
			},
			submit() {
				if (!this.content) {
					uni.showToast({
						title: "请输入外出理由",
						icon: "none",
					})
					return
				}
				let files = [],
					that = this;
				// 如果您不需要进行太多的处理，直接如下即可
				// files = this.$refs.uUpload.lists;
				if(!this.photo.id){
					uni.showToast({
						title:"请上传当前图片",
						icon:"none"
					})
					return
				}
				console.log(files)
				this.$axios('clock/clock', {
					type: 2,
					lat: that.lat,
					lon: that.lon,
					content: that.content,
					img: that.photo.id,
				}).then((res) => {
					// that.loadInfo();
					// const pages = getCurrentPages(); //获取页面栈
					// const beforePage = pages[pages.length - 2]; //前一个页面
					// // #ifdef H5
					// beforePage.loadInfo()
					// // #endif
					// // #ifndef H5
					// beforePage.loadInfo()
					// // #endif
					// uni.navigateBack()
					const that = this;
					    const pages = getCurrentPages().pop();//获取页面栈
					    const beforePage = pages[pages.length - 2];  //前一个页面
					    wx.navigateBack({ //跳转到前一个页面
					      delta:1,//前一个页面
					      success: function () {
					        //调用前一个页面的方法updateTime()。
					        // beforePage.onload(); 
					      },
						 });
				});
			},
			scuer() {
				this.show = true
			},
			confirm(e) {
				this.form.sucer = e[0].value

			}
		},
		mounted() {

		},
		//onHide:{},  //监听页面隐藏
		//onUnload:{},	//监听页面卸载
		//onPullDownRefresh:{},  //监听用户下拉动作，一般用于下拉刷新  page.json  "enablePullDownRefresh":true,//开启下拉刷新
		//onReachBottom:{}, //页面滚动到底部
		//onShareAppMessage:{}, 用户点击右上角分享

	}
</script>

<style scoped>
	.top_item {
		color: #333;
		font-size: 30upx;
		line-height: 100upx;
		padding-left: 32upx;
	}

	.input_set {
		padding: 0 32upx;
		border-bottom: 1px solid rgba(0, 0, 0, 0.1);
	}

	.inputs {
		display: block;
		text-align: right;
		color: #666;
		height: 80upx;
		padding-right: 10upx;
	}

	.lefttext {
		color: #34404A;
		font-size: 32upx;
	}

	.lefttext text {
		color: #f00;
		font-size: 30upx;
		display: inline-block;
		padding-right: 5upx;
	}

	.textare {
		color: #666;
		font-size: 26upx;
		padding-top: 20upx;
		padding-left: 20upx;
	}

	.z_button {
		position: fixed;
		width: 100%;
		bottom: 0;
		height: calc(100rpx + env(safe-area-inset-bottom));
		left: 0;
		z-index: 1;
		background: #fff;
		line-height: 100upx;
		background: #fff;
	}

	.but {
		width: 85%;
		background: #007AFF;
		border-radius: 20upx;
		text-align: center;
		line-height: 85upx;
		margin-top: 8upx;
		margin: auto;
		color: #fff;
		font-size: 32upx;
	}
</style>
